package se.webbzon.boltzmann.game.sequence.builder.dialogue;

import se.webbzon.boltzmann.game.object.dialogue.DialogueBackground;
import se.webbzon.boltzmann.game.object.dialogue.IntegerDialogue;
import se.webbzon.boltzmann.game.object.dialogue.layout.IntegerDialogueLayout;
import se.webbzon.boltzmann.game.sequence.IntegerDialogueSequenceNode;
import se.webbzon.boltzmann.game.sequence.Sequence;
import se.webbzon.boltzmann.game.sequence.SequenceNode;
import se.webbzon.boltzmann.game.sequence.builder.SequenceBuilder;
import se.webbzon.boltzmann.game.sequence.builder.SequenceRowDeflation;
import se.webbzon.oschi01.worldarea.WorldArea;

public class IntegerDialogueRow extends AbstractDialogueRow {
	
	// The name of the sequence row
	public static final String name = "integerDialogue";
	
	// The prefix and postfix text of the input
	private String prefix, postfix;
	
	// The minimal and maximal value of the integer dialogue
	private String minValue, maxValue;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new simple dialogue row. **/
	public IntegerDialogueRow(	SequenceBuilder builder,
								IntegerDialogueLayout layout, 
								DialogueBackground background,
								String text, 
								String prefix, String postfix,
								String minValue, String maxValue) {
		super(name,builder,layout,background,text);
		this.prefix = prefix;
		this.postfix = postfix;
		this.minValue = minValue;
		this.maxValue = maxValue;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the prefix text of the input dialogue. **/
	public String getPrefix() {
		return prefix;
	}

	/** Sets the prefix text of the input dialogue. **/
	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}

	/** Returns the postfix text of the input dialogue. **/
	public String getPostfix() {
		return postfix;
	}

	/** Sets the postfix text of the input dialogue. **/
	public void setPostfix(String postfix) {
		this.postfix = postfix;
	}
	
	/** Returns the minimal value of the integer dialogue. **/
	public String getMinValue() {
		return minValue;
	}

	/** Sets the minimal value of the integer dialogue. **/
	public void setMinValue(String minValue) {
		this.minValue = minValue;
	}

	/** Returns the maximal value of the integer dialogue. **/
	public String getMaxValue() {
		return maxValue;
	}

	/** Sets the maximal value of the integer dialogue. **/
	public void setMaxValue(String maxValue) {
		this.maxValue = maxValue;
	}

	@Override public int maxLinks() {
		return 1;
	}

	@Override public int minLinks() {
		return 0;
	}

	@Override public SequenceNode compile(WorldArea world, Sequence sequence) {
		IntegerDialogueLayout layout = (IntegerDialogueLayout) getLayout();
		IntegerDialogue dialogue = 
				new IntegerDialogue(layout,getBackground(),getText(),
									prefix,postfix,
									minValue,maxValue);
		world.createInstance(dialogue);
		return new IntegerDialogueSequenceNode(sequence,dialogue);
	}

	@Override public void bind(SequenceNode node, SequenceNode[] nodes) {
		final IntegerDialogueSequenceNode n = (IntegerDialogueSequenceNode) node;
		if (links() == 1) { 
			Integer branch = getLink(0);
			if (branch != null)
				n.setBranch(nodes[getLink(0)]);
		}
	}

	@Override public SequenceRowDeflation getDeflation() {
		return new IntegerDialogueRowDeflation(this);
	}

}
